<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // > - 求两数组去重后的交集
      let arr1 = [1, 2, 3, 4, 6, 6, 2, 1];
      let newArr1 = [...new Set(arr1)];
      let arr2 = [3, 2, 7, 9, 3, 2];
      let newArr2 = [...new Set(arr2)];
      let arr = [];

      //   function delFn(newArr1, newArr2, arr) {
      //     for (let i = 0; i < newArr1.length; i++) {
      //       console.log(newArr1[i]);
      //       for (let j = 0; j < newArr2.length; j++) {
      //         if (newArr1[i] == newArr2[j]) {
      //           arr.push(newArr1[i]);
      //         }
      //       }
      //     }
      //   }
      //   delFn(newArr1, newArr2, arr);

      //   for (let i = 0; i < newArr1.length; i++) {
      //     console.log(newArr1[i]);
      //     for (let j = 0; j < newArr2.length; j++) {
      //       if (newArr1[i] == newArr2[j]) {
      //         arr.push(newArr1[i]);
      //       }
      //     }
      //   }
      //   console.log(arr);

      // > - 求两数组去重后的并集
      //   function togerFn(newArr1, newArr2, arr) {
      //     arr = newArr1.concat(newArr2);
      //     console.log(arr);
      //   }
      //   togerFn(newArr1, newArr2, arr);

      // > - 求两数组去重后的差集

      function diffFn(newArr1, newArr2, arr) {
        let count = 0;
        for (let i = 0; i < newArr1.length; i++) {
          for (let j = 0; j < newArr2.length; j++) {
            if (newArr1[i] !== newArr2[j]) {
              count++;
            }
          }
          if (count === newArr2.length) {
            arr.push(newArr1[i]);
          }
          count = 0;
        }
      }
      diffFn(newArr1, newArr2, arr);
      console.log(arr);
    </script>
  </body>
</html>
